﻿// <copyright file="OutputBufferCollection.cs" company="TenneySoftware">
// Copyright (c) 2009 All Right Reserved
// </copyright>
// <author>Robert Tenney</author>
// <email>rob10e@yahoo.com</email>
// <date>April 2009</date>
// <summary>Collection for the output buffer.</summary>

// License:

// Product: Engine.csproj
// Author: Robert N. Tenney
// Copyright: 9/20/2009

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation version 2
// of the License.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

// This license covers all source code, binaries, and other materials related to this project
// unless specifically stated otherwise.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace TenneySoftware.Engine {
    /// <summary>
    /// Collection for the output buffer.
    /// </summary>
    public class OutputBufferCollection : Collection<string> {
        /// <summary>
        /// Initializes a new instance of the OutputBufferCollection class.
        /// </summary>
        public OutputBufferCollection() : base(new List<string>()) {
        }

        /// <summary>
        /// Searches the collection using the given Predicate.
        /// </summary>
        /// <param name="match">Predicate to use to search the collection.</param>
        /// <returns>True if the predicate finds a match.</returns>
        public string Find(Predicate<string> match) {
            List<string> items = (List<string>)Items;
            return items.Find(match);
        }

        /// <summary>
        /// Searches the collection using the given Predicate.
        /// </summary>
        /// <param name="match">Predicate to use to search the collection.</param>
        /// <returns>Index of the match.</returns>
        public int FindIndex(Predicate<string> match) {
            List<string> items = (List<string>)Items;
            return items.FindIndex(match);
        }

        /// <summary>
        /// Sorts the collection alphabetically.
        /// </summary>
        public void Sort() {
            List<string> items = (List<string>)Items;
            items.Sort();
        }

        /// <summary>
        /// Convert this Collection into an Array.
        /// </summary>
        /// <returns>An array of string.</returns>
        public string[] ToArray() {
            List<string> list = (List<string>)this.Items;
            string[] arr;
            arr = list.ToArray();
            return arr;
        }
    }
}
